package day20170424.ch01;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import org.junit.Test;

public class OutputStreamWriterTest {
	
	/**
	 * 转换流
	 * @throws Exception
	 */
	@Test
	public void outputStreamWriter(){
		//派出小部队
		OutputStream os = null;
		//派出大部队
		Writer w = null;
		try {
			//派出侦察兵
			File file = new File("txt/BufferedWriter.txt");
			//把侦察兵的信息告诉小部队，小部队去杀鬼子
			os = new FileOutputStream(file);
			//把小部队跟大部队结合起来，杀鬼子更快
			w = new OutputStreamWriter(os);
			String target = "中深软通123123123asdhashdashd啊是看得见啊好看的";
			//一次性杀完全部鬼子
			w.write(target);
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			if(null != w){
				try {
					//关闭大部队
					w.close();
				} catch (IOException e) {
					e.printStackTrace();
				}finally {
					if(null != os){
						try {
							//关闭小部队
							os.close();
						} catch (IOException e) {
							e.printStackTrace();
						}
					}
				}
			}
			
		}
	}
}
